package com.catmiao.spark.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_transform
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/2 11:48
 */
object RDD_Operator_18_transform {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)


    val rdd1 = sparkContext.makeRDD(List(("a", 1), ("b", 2), ("c", 3), ("d", 4)))
    val rdd2 = sparkContext.makeRDD(List(("a", 1), ("b", 2), ("d", 3), ("e", 4)))


    // join 两个数据源中 相同Key连接在一起形成tuple 【内连接】
    //      如果key没有匹配上则不会出现
    val rdd3: RDD[(String, (Int, Int))] = rdd1.join(rdd2)


    rdd3.collect().foreach(println)

    sparkContext.stop()
  }

}
